package com.oromwin.repos.server;

import java.io.DataInputStream;
import java.io.IOException;

import org.apache.commons.logging.Log;

import com.oromwin.repos.common.Common;
import com.oromwin.repos.common.Logger;
import com.oromwin.repos.common.ReposException;
import com.oromwin.repos.common.Common.Status;
import com.oromwin.repos.common.Common.ReposType;

@SuppressWarnings("unused")
public class ReposHeader {
    private Log _log = Logger.getLog(ReposHeader.class);
    
    private ReposType type = null;
    private Status action = null;
    private DataInputStream _dis = null;
    private enum Test { a, b, c }
    
    public ReposHeader(DataInputStream dis) {
        _dis = dis;
    }
    // TODO: need checksum to verify valid client or not 
    public void read() throws ReposException {
        try {
            byte[] header = new byte[Common.SIZE_OF_REPOS_HEADER];
            int readBytes = _dis.read(header, 0, Common.SIZE_OF_REPOS_HEADER);
            if (readBytes != Common.SIZE_OF_REPOS_HEADER) {
                throw ReposException.create(_log, String.format("Illegal size of header, readBytes {%d}", readBytes));
            }
            
            // byte actionByte = _dis.readByte();
        } catch (IOException e) {
            String message = String.format("Failed to read or parse header");
            throw ReposException.create(_log, e, message);
        }
    }
}    
